home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / GNUSUTIL.ZIP / src / system.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-17  |  4.9 KB  |  191 lines

  1. /* system-dependent definitions for shellutils programs.
  2.    Copyright (C) 89, 91, 92, 93, 1994 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. #include <sys/types.h>
  19. #include <sys/stat.h>
  20.  
  21. #ifdef STAT_MACROS_BROKEN
  22. #undef S_ISBLK
  23. #undef S_ISCHR
  24. #undef S_ISDIR
  25. #undef S_ISFIFO
  26. #undef S_ISLNK
  27. #undef S_ISMPB
  28. #undef S_ISMPC
  29. #undef S_ISNWK
  30. #undef S_ISREG
  31. #undef S_ISSOCK
  32. #endif /* STAT_MACROS_BROKEN.  */
  33.  
  34. #ifndef S_IFMT
  35. #define S_IFMT 0170000
  36. #endif
  37. #if !defined(S_ISBLK) && defined(S_IFBLK)
  38. #define    S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
  39. #endif
  40. #if !defined(S_ISCHR) && defined(S_IFCHR)
  41. #define    S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
  42. #endif
  43. #if !defined(S_ISDIR) && defined(S_IFDIR)
  44. #define    S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
  45. #endif
  46. #if !defined(S_ISREG) && defined(S_IFREG)
  47. #define    S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
  48. #endif
  49. #if !defined(S_ISFIFO) && defined(S_IFIFO)
  50. #define    S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
  51. #endif
  52. #if !defined(S_ISLNK) && defined(S_IFLNK)
  53. #define    S_ISLNK(m) (((m) & S_IFMT) == S_IFLNK)
  54. #endif
  55. #if !defined(S_ISSOCK) && defined(S_IFSOCK)
  56. #define    S_ISSOCK(m) (((m) & S_IFMT) == S_IFSOCK)
  57. #endif
  58. #if !defined(S_ISMPB) && defined(S_IFMPB) /* V7 */
  59. #define S_ISMPB(m) (((m) & S_IFMT) == S_IFMPB)
  60. #define S_ISMPC(m) (((m) & S_IFMT) == S_IFMPC)
  61. #endif
  62. #if !defined(S_ISNWK) && defined(S_IFNWK) /* HP/UX */
  63. #define S_ISNWK(m) (((m) & S_IFMT) == S_IFNWK)
  64. #endif
  65.  
  66. #ifdef HAVE_UNISTD_H
  67. #include <unistd.h>
  68. #endif
  69.  
  70. #ifdef OS2
  71.  
  72. #include <process.h>
  73. #include <stdlib.h>
  74. #include <pwd.h>
  75.  
  76. #ifdef NICE
  77. #define execvp(n, a)        {int rc = spawnvp(P_WAIT, n, a); if (rc != -1) exit(rc);}
  78. #else
  79. #define execvp(n, a)        spawnvp(P_OVERLAY, n, a)
  80. #endif
  81.  
  82. #define PATH_MAX            260
  83. #define NAME_MAX            256
  84.  
  85. #define getgid()            0
  86. #define getuid()            0
  87. #define getegid()           0
  88. #define geteuid()           0
  89. #define getpwnam(x)         (dummy_pw.pw_name = getlogin(), &dummy_pw)
  90. #define getpwuid(x)         (dummy_pw.pw_name = getlogin(), &dummy_pw)
  91. #define getgrgid(x)         (&dummy_gr)
  92. #define getgroups(n,p)      (*p = 0, 1)
  93. #define getugroups(n,p,u)   (*p = 0, 1)
  94. #define getlogin()          (getenv("LOGNAME") ? getenv("LOGNAME") : "root")
  95.  
  96. struct group {
  97.   char *gr_name;
  98.   gid_t gr_uid;
  99. };
  100.  
  101. static struct group dummy_gr = {"root", 0};
  102. static struct passwd dummy_pw = {"root", 0, 0};
  103.  
  104. #define ttyname(arg)        (isatty(0) ? "con" : NULL)
  105.  
  106. #define main os2main
  107.  
  108. #else /* not OS2 */
  109.  
  110. #ifndef _POSIX_VERSION
  111. char *getlogin ();
  112. char *ttyname ();
  113. off_t lseek ();
  114. uid_t geteuid ();
  115. #endif /* _POSIX_VERSION */
  116.  
  117. #endif /* OS2 */
  118.  
  119. #if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
  120. #include <string.h>
  121. #ifndef index
  122. #define index strchr
  123. #endif
  124. #ifndef rindex
  125. #define rindex strrchr
  126. #endif
  127. #ifndef bcopy
  128. #define bcopy(from, to, len) memcpy ((to), (from), (len))
  129. #endif
  130. #ifndef bzero
  131. #define bzero(s, n) memset ((s), 0, (n))
  132. #endif
  133. #else
  134. #include <strings.h>
  135. #endif
  136.  
  137. #include <errno.h>
  138. #ifdef STDC_HEADERS
  139. #include <stdlib.h>
  140. #else
  141. char *getenv ();
  142. extern int errno;
  143. #endif
  144.  
  145. #ifdef HAVE_FCNTL_H
  146. #include <fcntl.h>
  147. #else
  148. #include <sys/file.h>
  149. #endif
  150.  
  151. #ifndef F_OK
  152. #define F_OK 0
  153. #define X_OK 1
  154. #define W_OK 2
  155. #define R_OK 4
  156. #endif
  157.  
  158. #include <ctype.h>
  159.  
  160. #include "version.h"
  161. #define print_version(x) \
  162.   fprintf(stderr, "\nGNU %s, %s\n\n", x, version_string + 4)
  163.  
  164. #if defined (STDC_HEADERS) || (!defined (isascii) && !defined (HAVE_ISASCII))
  165. #define ISASCII(c) 1
  166. #else
  167. #define ISASCII(c) isascii(c)
  168. #endif
  169.  
  170. #ifdef isblank
  171. #define ISBLANK(c) (ISASCII (c) && isblank (c))
  172. #else
  173. #define ISBLANK(c) ((c) == ' ' || (c) == '\t')
  174. #endif
  175. #ifdef isgraph
  176. #define ISGRAPH(c) (ISASCII (c) && isgraph (c))
  177. #else
  178. #define ISGRAPH(c) (ISASCII (c) && isprint (c) && !isspace (c))
  179. #endif
  180.  
  181. #define ISPRINT(c) (ISASCII (c) && isprint (c))
  182. #define ISDIGIT(c) (ISASCII (c) && isdigit (c))
  183. #define ISALNUM(c) (ISASCII (c) && isalnum (c))
  184. #define ISALPHA(c) (ISASCII (c) && isalpha (c))
  185. #define ISCNTRL(c) (ISASCII (c) && iscntrl (c))
  186. #define ISLOWER(c) (ISASCII (c) && islower (c))
  187. #define ISPUNCT(c) (ISASCII (c) && ispunct (c))
  188. #define ISSPACE(c) (ISASCII (c) && isspace (c))
  189. #define ISUPPER(c) (ISASCII (c) && isupper (c))
  190. #define ISXDIGIT(c) (ISASCII (c) && isxdigit (c))
  191.